/* eslint-disable eqeqeq */
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import { lineDatils } from "../API/busAPI";
import { Card } from "antd-mobile";
import Header from "../../Header";

export default function LineService() {
  const history = useHistory();
  const [bus, setBus]: any = useState({});

  useEffect(() => {
    handle();
  }, []);

  const str = history.location.pathname;
  const id = str.substring(str.lastIndexOf("/") + 1);

  const handle = async () => {
    const res = await lineDatils(id);
    console.log(res);
    if (res.data.code == 200) {
      setBus(res.data.data);
    }
  };

  return (
    <div>
      <Header title="线路详情"></Header>
      <div className="xz-content">
        <Card title={bus.name} className="xz-card">
          <div>
            <span>首发时间：{bus.startTime}</span> ——{" "}
            <span>末班时间：{bus.endTime}</span>
          </div>
          <div>
            <span>起点：{bus.first}</span> ———— <span>终点：{bus.end}</span>
          </div>
          <div>里程：{bus.mileage + "km"} </div>
          <div>价格：{"￥" + bus.price}</div>
        </Card>
      </div>
    </div>
  );
}
